import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const router = new VueRouter({
    routes: [
        {
            name: 'login',
            path: '/login',
            component: () => import('@/components/day07/login.vue')
        },
        {
            name: 'index',
            path: '/index',
            component: () => import('@/components/day07/index.vue'),
            children: [

                {
                    name: 'user',
                    path: 'user',
                    component: () => import('@/components/day07/user.vue')
                },
                {
                    name: 'order',
                    path: 'order',
                    component: () => import('@/components/day07/order.vue')
                },
                {
                    name: 'role',
                    path: 'role',
                    component: () => import('@/components/day07/role.vue')
                },
                {
                    name: 'goods',
                    path: 'goods',
                    component: () => import('@/components/day07/goods.vue')
                },
                {
                    name: 'setting',
                    path: 'setting',
                    component: () => import('@/components/day07/setting.vue')
                }
            ]

        }
    ]
})

router.beforeEach((to, from, next) => {
    console.log(to);
    if (to.path == '/login') {
        next()
    } else {
        let token = localStorage.getItem('taken')
        console.log(token);
        if (token) {

            next()
        } else {
            next({ path: '/login' })
        }
    }
})
export default router